@extends('admin.layouts.head')
@section('content')
    <body>
    <div id="app">
        <div class="wrapper -header-fixed">

        @include('admin.layouts.navbar')
        @include('admin.layouts.sidebar')

        <!-- 内容页开始-->
            <div class="content-container">
                <div class="container-fluid">
                    <div class="page-content">

                        <nav aria-label="breadcrumb">
                            <ol class="breadcrumb">
                                <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">仪表盘</a></li>
                                <li class="breadcrumb-item"><a href="{{ route('admin.users.index') }}">用户列表</a></li>
                                <li class="breadcrumb-item active" aria-current="page">添加</li>
                            </ol>
                        </nav>

                        <div class="card">
                            <div class="card-body">

                                <div class="row">
                                    <div class="col-lg-5">
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>用户名：</label>
                                                <input type="text" class="form-control" id="username" maxlength="255" placeholder="请输入您的用户名" required>
                                            </div>
                                            <div class="form-group">
                                                <label>电子邮箱：</label>
                                                <input type="email" class="form-control" id="email" maxlength="255"
                                                       placeholder="请输入您的要创建的电子邮箱地址" required>
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>密码：</label>
                                                <input type="password" class="form-control" id="password" maxlength="16"
                                                       placeholder="请输入密码" required>
                                            </div>
                                        </div>
                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>确认密码：</label>
                                                <input type="password" class="form-control" id="password_confirmation"
                                                       maxlength="16" placeholder="再次输入密码" required>
                                            </div>
                                        </div>

                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <label>金额：</label>
                                                <input type="text" class="form-control" id="money" value="0.00" placeholder="设置用户金额" required>
                                            </div>
                                        </div>

                                        <div class="col-lg-12">
                                            <div class="form-group">
                                                <button class="btn btn-primary" onclick="operation_tip()">提交</button>
                                            </div>
                                        </div>
                                    </div>

                                </div> <!-- .row -->
                            </div> <!-- .card-body -->
                        </div> <!-- .card -->

                    </div> <!-- .page-content -->
                </div> <!-- .container-fluid -->
            </div> <!-- .content-container -->
        </div> <!-- .wrapper -->
    </div> <!-- #app -->

    <script src="{{ mix('js/app.js') }}"></script>
    <script src="{{ asset('/js/main.js') }}"></script>
    <script>

        let isLoading = false;

        //提交
        function submit() {

            if (! $('#username').val()) {
                toast('用户名 不能为空');
                return false
            }
            if (! $('#email').val()) {
                toast('邮箱地址 不能为空');
                return false
            }
            if (! $('#password').val()) {
                toast('密码 不能为空。');
                return false
            }
            if (! $('#password_confirmation').val()) {
                toast('确认密码 不能为空。');
                return false
            }
            if ( ! $('#money').val() ) {
                toast('金额 不能为空。');
                return false
            }

            if (isLoading === false) {
                isLoading = true;

                axios.post('{{ route('admin.users.store') }}', {
                    username: $('#username').val(),
                    email: $('#email').val(),
                    password: $('#password').val(),
                    password_confirmation: $('#password_confirmation').val(),
                    money: $('#money').val(),
                })
                    .then(function (response) {
                        isLoading = false;
                        toast(response.data.message);
                    })
                    .catch(function (error) {
                        isLoading = false;
                        $.each(error.response.data.errors, function (index, object) {
                            toast(object[0]);
                            return false;
                        });
                    })
            }
        }
    </script>

    </body>

@endsection
